package com.example.mysampleapp.activity;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;

import com.example.myfirstapp.R;
import com.example.mysampleapp.fragment.BookDescFragment;

public class BookDescActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_book_desc);

		// Retrieve the book index from the Activity Intent
		Intent intent = getIntent();
		int bookIndex = intent.getIntExtra("bookIndex", -1);
		if (bookIndex != -1) {
			// Use FragmentManager to access BookDescFragment
			FragmentManager fm = getFragmentManager();
			BookDescFragment bookDescFragment = (BookDescFragment) fm
					.findFragmentById(R.id.fragmentDescription);
			// Display the book title
			bookDescFragment.setBook(bookIndex);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.book_desc, menu);
		return true;
	}

}
